/*
*	Copyright (C) 2014  Julio Montes, Mario Carrillo
*	
*	Julio Montes e-mail: imc.coder@gmail.com 
*
*	Mario Carrillo e-mail: mario_90ago@live.com.mx
*
*	BSD 3-Clause License
*/

#define ID_OK 1023
#define ID_CANCEL 2222
#include "alliance/include/FileSelector.h"


namespace alliance
{

FileSelector::FileSelector( const wxString& title, wxArrayString arr,wxString path_file,wxString LabelFileOut,
                            int TypeFile, string &FIn, string &FOut, wxString &path_wx)
    : wxDialog(NULL,wxID_ANY,title,wxDefaultPosition,wxSize( 320,250 ) )
{



    Connect(ID_OK,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(FileSelector::OnOk));
    Connect(ID_CANCEL,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(FileSelector::OnCancel));


    FI=&FIn;
    FO=&FOut;
    p_fo=&path_wx;
    p_file=path_file;
    wxPanel *Panel=new wxPanel( this );



    if(TypeFile==1)
    {
        Instruction=new wxStaticText(Panel,wxID_ANY,wxT("Input Output Conector placement description\n                        Select File "),wxPoint(10,10),wxDefaultSize);
    }
    else
    {
        Instruction=new wxStaticText(Panel,wxID_ANY,wxT("Creat Pattern file "),wxPoint(90,20),wxDefaultSize);
    }

    files=new wxComboBox(Panel,wxID_ANY,arr[0],wxPoint(50,60), wxSize(200,30),arr,wxCB_READONLY);
    Instruction2=new wxStaticText(Panel,wxID_ANY,LabelFileOut,wxPoint(10,110),wxDefaultSize);
    FieldNameFileOut=new wxTextCtrl(Panel,wxID_ANY,wxT(""),wxPoint(50,140),wxSize(200,30));
    ButtonOk=new wxButton(Panel,ID_OK, wxT("Ok"),wxPoint(160,190));
    ButtonCancel=new wxButton(Panel,ID_CANCEL, wxT("Cancel"),wxPoint(50,190));
    //ctor

}





void FileSelector::OnOk( wxCommandEvent& event )
{

    wxString fn=p_file+files->GetValue();
    wxString fnO=p_file+FieldNameFileOut->GetValue();
    *p_fo=fnO;

    *FI=string(fn.mb_str());
    *FO=string(fnO.mb_str());

    if(!wxFileExists(fn))
    {
        wxMessageBox(wxT("Error"));
        EndModal(-1);
//return ;
    }


    else if(FieldNameFileOut->GetValue().IsEmpty())
    {
        wxMessageBox(wxT("Error Name File Out"));
        EndModal(-1);

        //return ;
    }


    EndModal(wxID_OK );
}

void FileSelector::OnCancel(wxCommandEvent& event)
{
    EndModal(wxID_OK );
}


FileSelector::~FileSelector()
{

}




}









/*

#include "alliance/include/FileSelector.h"
#include "alliance/include/projectmgr.h"

#define ID_OK 1023
#define ID_CANCEL 2222

namespace alliance
{
BEGIN_EVENT_TABLE(FileSelector,wxDialog)
    EVT_BUTTON(ID_OK,FileSelector::OnOk)
    EVT_BUTTON(ID_CANCEL,FileSelector::OnCancel)
END_EVENT_TABLE()

*/

